import React, { useState, useEffect, useContext, createContext, useReducer } from 'react'
function counterReducer(state, action) {
  switch (action.type) {
    case 'add':
      return state + 1
    default:
      return state
  }
}
export default function Test() {
  // 1.useState的替代品
  const [state, dispatch] = useReducer(counterReducer, 0)
  return (
    <>
      {state}
      <hr />
      <button onClick={() => dispatch({ type: 'add' })}>加</button>
    </>
  )
}
